package com.jk.customer.controller;

import com.jk.customer.entity.TreeEntity;
import com.jk.customer.entity.UserEntity;
import com.jk.customer.service.TreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Controller
public class TreeController {
    @Autowired
    private TreeService treeService;

    /**
     * 树列表查询
     *
     * @param pid
     * @return
     */
    @RequestMapping("getTree")
    @ResponseBody
    public List<TreeEntity> getTree(Integer pid,HttpSession session){
        return treeService.getTree(pid,session);
    }

    /**
     * 登录
     */
    @RequestMapping("login")
    @ResponseBody
    public Map<String,Object> login(UserEntity user, HttpSession session, HttpServletRequest request){
        return treeService.login(user,session);
    }

    @RequestMapping(value = "/toadd")
    public String toadd(){
        return "addFindPriceChr";
    }

    @RequestMapping(value = "/toLayout")
    public String toLayout(HttpServletRequest request, Model model){
        UserEntity user = (UserEntity)request.getSession().getAttribute("user");
        model.addAttribute("user",user);
        return "layout";
    }

    @RequestMapping(value = "/toMypage")
    public String toMyPage(){
        return "totalPages";
    }

    @RequestMapping(value = "/registerUser")
    @ResponseBody
    public Map<String, Object > registerUser(UserEntity user){
        return treeService.registerUser(user);
    }

    @RequestMapping(value = "/addUserInfo")
    @ResponseBody
    public Map<String, Object > addUserInfo(UserEntity user){
        return treeService.addUserInfo(user);
    }

}
